import { director, game, log, Node } from "cc";
import { GlobelDataMgr, SceneName } from "./GlobelDataMgr";
import { LogMgr } from "../components/LogMgr";
export class GlobelMgr {
    private static _instance:GlobelMgr;
    private _persistentNode:Node;
    private _layerNames:Array<string> = ["layer_ui_bottom","layer_ui_middle","layer_ui_top"];
    public static get instance():GlobelMgr{
        if(this._instance==null)
        {
            this._instance = new GlobelMgr();
        }
        return this._instance;
    }
    /**设置常驻节点*/
    public setPersistentNode(persistentNode:Node):void{
        this._persistentNode = persistentNode;
        director.addPersistRootNode(this._persistentNode);
    }
    /**获取常驻节点*/
    public getPersistentNode():Node{
        return this._persistentNode;
    }
    /**切换场景*/
    public switchingScenes(sceneName:SceneName):void{
        LogMgr.log("进入场景"+sceneName);
        director.loadScene(sceneName);
        GlobelDataMgr.instance.setSceneName(sceneName);
    }
    public getLayer(layer:Layer):Node{
        if(layer!=Layer.tips)
        {
            let mainNode:Node;
            switch(GlobelDataMgr.instance.getSceneName())
            {
                case SceneName.main:
                    mainNode = director.getScene().getChildByName("Canvas");
                break;

                case SceneName.hall:
                    mainNode = director.getScene().getChildByName("Canvas");
                break;
            }
            return  mainNode.getChildByName(this._layerNames[layer-1]);
        }else{
            return this._persistentNode;
        }
    }
}
export enum Layer {
    UI_bottom = 1,
    UI_middle = 2,
    UI_top = 3,
    tips = 4,//常驻节点
}
